// 创建对象
const obj1 = new Object(); //构造函数
const obj2 = {}; //对象字面量

//定义属性 js对象 可以看成键值对的集合
const user = {
  name: "张三", // 键值对
  age: 20,
};
//访问
user.age = 21;
console.log(user.age);
console.log(user["age"]);
//添加
user.school = "zsc";
user["is Admin"] = true;
console.log(user);
//删除
//delete user.school;
delete user["school"];
console.log(user);
let propName = "name";
console.log(user[propName]);
propName = "age";
console.log(user[propName]);

for (let key in user) {
  //console.log(key + ":" + user[key]);
  console.log(`${key}:${user[key]}`); //模式字符串
}

//对象的引用
let user1 = user;
user1.age = 1;
console.log(user);

const dog = {
  name: "大黄",
  age: 2,
  other: {
    color: "white",
  },
};
const dog1 = dog;
++dog1.age;
console.log(dog);

// 创建对象的副本
const dog2 = {};
for (key in dog) {
  dog2[key] = dog[key];
}
dog2.age = 4;
console.log(dog.age);
const dog3 = Object.assign({}, dog);
dog3.age = 4;
console.log(dog.age);
